package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
@ApiOperation("套餐管理")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /*分页查询套餐*/
    @ApiOperation("分页查询套餐")
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("分页查询: {}",setmealPageQueryDTO);
        PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    /*根据id查询套餐*/
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public Result<SetmealDTO> getById(@PathVariable Long id){
        log.info("根据id查询: {}",id);
        SetmealDTO setmealDTO = setmealService.getById(id);
        return Result.success(setmealDTO);
    }




    /*新增套餐*/
    @ApiOperation("新增套餐")
    @PostMapping
    public Result save(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐: {}",setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }
    /*批量删除套餐*/
    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public Result delete(@RequestParam Long[] ids){
        log.info("批量删除套餐: {}",ids);
        setmealService.deleteBentch(ids);
        return Result.success();
    }

    /*修改套餐*/
    @ApiOperation("修改套餐")
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐: {}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }

}
